/**
 * Audit the request from clients
 */
var toolUtil = require('../common/utils/toolUtil');
var Audits = mongoose.model('backoffice_audits');

exports.doAuditRequest = function (req, res, next) {
    if (enableAuditRequest == 'Yes' && req.url.indexOf('/appLog/') == -1) {
        logger.debug('Request from:\'' + req.ip + '\'on resource \'' + req.url + '\'');
    }
    req.requestStartDataTime = new Date().getTime();
    //把消息按规定的格式放到Message Queue中；
    /**
     * httpMethod / URL / userID / Body / dateTime
     */
    var tempArray = req.url.split('/');
    var token = tempArray[tempArray.length - 2];
    var message = {
        "httpMethod": req.method,
        "ip": req.ip,
        "url": req.url,
        "userID": toolUtil.getUserObjIdByToken(token),
        "body": req.body,
        "dateTime": new Date()
    };
    //toolUtil.putMessageRequestMQ(message);

    //Pass to next function;
    next();
}
